from time import sleep

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://www.baidu.com/')
sleep(2)
driver.find_element_by_link_text('新闻').click()
sleep(2)

hds=driver.window_handles
driver.switch_to.window(hds[1])
#切换到新闻界面
driver.find_element_by_link_text('军事').click()
sleep(2)

driver.find_element_by_link_text('量子效应有多神秘？反氢粒子来告诉你').click()
sleep(2)
print(hds)
driver.close()

driver.switch_to.window(hds[0])
#切换到百度界面
driver.find_element_by_id('kw').send_keys('selenium')
su=driver.find_element_by_id('su')
su.click()
sleep(3)
driver.quit()